<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<link rel="stylesheet" media="screen" href="css/docs.css" />
<link rel="stylesheet" media="screen"
	href="lib/jqplot/jquery.jqplot.min.css" />
<!-- jQplot SETUP -->
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/jqplot/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="lib/jqplot/jquery.jqplot.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.barRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.highlighter.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.pointLabels.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.pieRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.donutRenderer.min.js"></script>
<script type="text/javascript"
	src="lib/jqplot/plugins/jqplot.bubbleRenderer.min.js"></script>
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<script type="text/javascript"
	src="lib/datatables/js/jquery.dataTables.js"></script>


<script type="text/javascript">
function loadChartImage(title,value) {
	/* 	var profits = [ 87.65, 98.40, 65.39, 93.20, 78.00, 67.98,
				78.45, 89.56, 87.10, 69.56, 96.20, 100 ];
		var tickslabel = [ '一月', '二月', '三月', '四月', '五月', '六月', '七月',
				'八月', '九月', '十月', '十一月', '十二月' ]; */
		var profits = value;
	   	var tickslabel = title;
		var ylabel = [ 'Profits' ];

		//line with some options
		var chart2 = $.jqplot('chart2', [ profits ], {
			title : '考核历史数据',
			legend : {
				show : true,
				labels : [ '定性考核' ],
				location : 'ne'
			},
			axes : {
				xaxis : {
					renderer : $.jqplot.CategoryAxisRenderer,
					ticks : tickslabel
				},
				yaxis : {
					tickOptions : {
						formatString : '%.2f 分'
					}
				}
			},
			highlighter : {
				show : true,
				sizeAdjust : 7.5,
				tooltipAxes : 'y'
			},
			cursor : {
				show : false
			}
		});

	}
		
	function loadScoreLine(showType){
		$.ajax({
	        type:"get",
	        url:"/ajax/qualadjustscore_list.xhtml?periodEnum=${type}&workId=${workId}&showYearlyEnum=" + showType,
	        //data: "name=John&location=Boston",
	        dataType:"json",
	        success:function (data) {
	        	if(data != null){
	        		$("#chart2").html("");
	        		loadChartImage(data.title,data.value);
	        	}
	        }
	    });
	}
	$(document).ready(function(){
		loadScoreLine("present_year");
	});
</script>
<!-- jQplot SETUP END -->
<h1 class="page-title">定性考核-考核打分-特别审批打分</h1>
<div class="container_12 clearfix">
	<section class="portlet grid_12 leading docs">
		<header>
			<h2>定性考核分数特别审批打分</h2>
		</header>
		<section>

			<DIV class="portlet">
				<header>
					<h5_n>${employeeinfoWork.baseId.name}</h5_n>
					<h2>
						<s:if test="#request.employeeinfoWork.baseId.sex == \"0\"">先生</s:if>
						<s:else>女士</s:else>
					</h2>
				</header>
				<section class="clearfix">


					<div class="grid_2 alpha" style="text-align: center">
						<img src="${employeeinfoWork.baseId.facePath}" width="120"
							height="135" onerror="this.src='${ctx}/images/Avatar.jpg'" />

					</div>
					<div class="grid_3">
						<dl>
							<dt>岗位</dt>
							<dd>
								<h6>${employeeinfoWork.duty.dutyName}</h6>
							</dd>
							<dt>员工号</dt>
							<dd>
								<h6>${employeeinfoWork.workNo}</h6>
							</dd>
							<dt>职等</dt>
							<dd>
								<h6>${employeeinfoWork.grade.gradeName}</h6>
							</dd>
						</dl>
					</div>
					<div class="grid_3">
						<dl>
							<dt>部门</dt>
							<dd>
								<h6>${employeeinfoWork.organization.fullName}</h6>
							</dd>
							<dt>职务</dt>
							<dd>
								<h6>${employeeinfoWork.duty.dutyName}</h6>
							</dd>
							<dt>职级</dt>
							<dd>
								<h6>${employeeinfoWork.gradeLevel.gradeSort}</h6>
							</dd>
						</dl>
					</div>
					<div class="grid_3 omega">
						<dl>
							<dt>工龄</dt>
							<dd>
								<h6>${employeeinfoWork.workAge}</h6>
							</dd>
							<dt>考核记录</dt>
							<dd>
								<h6>92分</h6>
								<select id="form-timezone" style="opacity: 0;"
									onchange="loadScoreLine(this.value)">
									<option value="present_year">显示本年度</option>
									<option value="last_year">显示上年度</option>
									<option value="all">显示全部</option>
								</select>
							</dd>

						</dl>
					</div>


				</section>
			</DIV>

			<div class="leading">
				<div class="jqPlot" id="chart2" style="width: 100%; height: 200px;"></div>
			</div>
			<div class="leading">
				<form id="post_form">
					<s:if test="#request.examQualScore != null">
						<input type="hidden" id="scoreId" name="scoreId" value="${examQualScore.id}" />
					</s:if>
					<s:else>
						<input type="hidden" id="scoreId" name="scoreId" value="-1" />
					</s:else>
					<input type="hidden" name="workId" value="${workId}" /> <input
						type="hidden" name="type" value="${type}" /> <input type="hidden"
						name="periodDesc" value="${periodDesc}" /> 
						<input type="hidden" name="currentAuditingId" value="${currentAuditingId}"/>
						<input type="hidden" name="currentAuditerUserId" value="${currentAuditerUserId}"/>
						<input type="hidden" name="currentAuditingDutyId" value="${currentAuditingDutyId}" />
					<table class="display" id="example">
						<thead>
							<tr>
								<th><strong>考核项目</strong></th>
								<th>占比</th>
								<s:if
									test="#request.examQualStandardSets!=null and #request.examQualStandardSets.size() > 0">
									<s:iterator value="#request.examQualStandardSets" var="qss"
										status="sta">
										<th>${qss.name}(${qss.scoreStart}-${qss.scoreEnd})</th>
									</s:iterator>
								</s:if>
								<th style="min-width: 60px">原始分</th>
								<th style="min-width: 60px">特批分分</th>
							</tr>
						</thead>
						<tbody>
							<s:if
								test="#request.examQualStandardSets==null or #request.examQualStandardSets.size() <= 0">
								<tr>
									<td>没有考核标准数据</td>
								</tr>
							</s:if>
							<s:else>
								<s:if
									test="#request.examQualScoreDetails==null or #request.examQualScoreDetails.size() <= 0">
									<tr>
										<td>暂无数据</td>
									</tr>
								</s:if>
								<s:else>
									<s:iterator value="#request.examQualScoreDetails" var="qis"
										status="sta">
										<s:if test="#sta.even">
											<tr class="gradeA">
										</s:if>
										<s:else>
											<tr class="gradeC">
										</s:else>
										<td>${qis.title}</td>
										<td><div id="progress2" class="progress"
												style="min-width: 50px">
												<span style="width: ${qis.percentage}%;"><b>${qis.percentage}%</b></span>
											</div></td>
										<s:if test="#request.examQualStandardSets.size() == 1">
											<td>${qis.desc1}</td>
										</s:if>
										<s:elseif test="#request.examQualStandardSets.size() == 2">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 3">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 4">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 5">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 6">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
											<td>${qis.desc6}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 7">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
											<td>${qis.desc6}</td>
											<td>${qis.desc7}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 8">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
											<td>${qis.desc6}</td>
											<td>${qis.desc7}</td>
											<td>${qis.desc8}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 9">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
											<td>${qis.desc6}</td>
											<td>${qis.desc7}</td>
											<td>${qis.desc8}</td>
											<td>${qis.desc9}</td>
										</s:elseif>
										<s:elseif test="#request.examQualStandardSets.size() == 10">
											<td>${qis.desc1}</td>
											<td>${qis.desc2}</td>
											<td>${qis.desc3}</td>
											<td>${qis.desc4}</td>
											<td>${qis.desc5}</td>
											<td>${qis.desc6}</td>
											<td>${qis.desc7}</td>
											<td>${qis.desc8}</td>
											<td>${qis.desc9}</td>
											<td>${qis.desc10}</td>
										</s:elseif>
										<s:else>
											<td></td>
										</s:else>
										<td><input type="text" value="${qis.rawScore}"
											style="width: 35px" value="79" disabled="disabled"/></td>
										<td><input type="hidden" name="itemId"
											value="${qis.itemId}" /> <s:if
												test="#request.examQualScore.adjustScore != null">
												<input type="hidden" value="${qis.adjustScore}" />
												<input type="text" name="txt_adjustScore"
													style="width: 35px" value="${qis.adjustScore}"
													onchange="updateAdjustTotalScore(this,${qis.percentage})" />
											</s:if> <s:else>
												<input type="hidden" value="0" />
												<input type="text" name="txt_adjustScore"
													style="width: 35px" value="0"
													onchange="updateAdjustTotalScore(this,${qis.percentage})" />

											</s:else></td>
										</tr>
									</s:iterator>
								</s:else>
							</s:else>
							<tr class="gradeA">
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td>&nbsp;</td>
								<td
									style="font-size: 16px; font-weight: bold; text-align: right">总分：</td>
								<td class="gradeX"><input type="text"
									style="width: 55px; font-size: 16px; font-weight: bold;"
									value="${examQualScore.rawScore}" disabled="disabled" /></td>
								<td class="gradeX"><s:if
										test="#request.examQualScore.adjustScore != null">
										<input type="hidden" id="adjustTotalScore"
											name="adjustTotalScore" value="${examQualScore.adjustScore}" />
										<input id="showAdjustTotalScore" type="text"
											style="width: 55px; font-size: 16px; font-weight: bold;"
											value="${examQualScore.adjustScore}" disabled="disabled" />
									</s:if> <s:else>
										<input type="hidden" id="adjustTotalScore"
											name="adjustTotalScore" value="0" />
										<input id="showAdjustTotalScore" type="text"
											style="width: 55px; font-size: 16px; font-weight: bold;"
											value="0" disabled="disabled" />
									</s:else></td>
							</tr>
						</tbody>
					</table>
				</form>
			</div>
			<div class="clear"></div>
			<div class="grid_12">


				<div class="form-action clearfix">
					<s:if test="#request.canAudit == true && #request.examQualScore.adjustScore > 0">
						<p>
							<div class="selector" id="uniform-form-timezone"><select id="audit_select">
								    <option value="1">同意特批</option>
								    <option value="2">不同意特批</option>
								    <s:if test="#request.lastAuditer == false">
								    	<option value="3">往上级部门提交特批</option>
								    </s:if>
							    </select>
						    </div>
						    
                            <a href="javascript:void(0)" class="button" onclick="handleSpeicalAudit()"><span class="icon" style="background:url(images/img/accept.png)">&nbsp;</span>确认</a>
							<s:if test="#request.examQualScore.currentAuditingId != null && #request.examQualScore.currentAuditingId == #request.currentAuditingId">
						    	已审批结果：${examQualScore.currentAuditStatus.name}
						    </s:if>
						</p>
					</s:if>
					
					<s:if test="#request.allowSpecialScore == true">
						<p>
							<a class="button" href="javascript:void(0)" onclick="checkForm()"><span
								style="background: url(images/img/accept.png)" class="icon">&nbsp;</span>确认特别审批打分</a>
	
							<a href="javascript:void(0)" onclick="historyBack()"
								class="button"><span class="icon"
								style="background: url(images/img/arrow_undo.png)">&nbsp;</span>返回</a>
						</p>
					</s:if>
				</div>

			</div>
			<h4>&nbsp;</h4>
		</section>
	</section>
</div>
<script type="text/javascript">
	function historyBack(){
		location.href = "${ctx}/index.xhtml#exam/exam_score.xhtml?p=qual_as&type=${type}&periodDesc=${periodDesc}&workId=${workId}";
	}
	
	function updateAdjustTotalScore(eventObject,percentage){
		if(isNaN(eventObject.value) || parseFloat(eventObject.value) < 0 || parseFloat(eventObject.value) > 100){
			alert('请输入正确的打分值');
			eventObject.focus();
			return;
		}
		$("#showAdjustTotalScore").val(parseFloat($("#showAdjustTotalScore").val()) - parseFloat($(eventObject).prev("input").val()) * (percentage / 100) + parseFloat(eventObject.value) * (percentage / 100));
		$("#adjustTotalScore").val($("#showAdjustTotalScore").val());
		$(eventObject).prev("input").val(eventObject.value);
	}

	function checkForm() {
		var validated = true;
		$("input[name='txt_adjustScore']").each(function(){
			if($(this).val().trim() == ""){
				validated = false;
			}
		});	
		if(!validated){
			alert("你还有没有给予评分的选项，请仔细评分.");
			return;
		}		
		var url = "${ctx}/exam/post_qualdistscore.xhtml?organizationId=${organizationId}&scoreId=" + $("#scoreId").val();
		$.ajax(url, {
		    type:"POST",
		    data:$("#post_form").serialize(),
		    dataType:"html",
		    cache:false,
		    success:function(a) {
		        alert('评分成功.');
                window.location.href = "${ctx}/index.xhtml#exam/exam_score.xhtml?p=qual_as&type=${type}&periodDesc=${periodDesc}&workId=${workId}";
		    },
		    error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert('提交申请发生异常,请联系管理人员.');
            },
		    complete:function(b) {
		    }
		});
	}
	// 处理特别审批打分 
	function handleSpeicalAudit(){
		var content = "";
		//var auditStatus = $("input[type='radio'][@name='audit_radio'][checked]").val();
		var auditStatus = "";

        //构造一个通用的AuditBase对象 
        var data = {
            "currentAuditingId":${currentAuditingId},
            "currentAuditerUserId":${currentAuditerUserId},
            "currentAuditingDutyId":${currentAuditingDutyId},
            "organizationId":"${organizationId}",
            "currentAuditType":"${currentAuditType}",
            "auditStatus":$("#audit_select").val(),
            "scoreId":$("#scoreId").val()
        };
        var url = "${ctx}/public/qual_score_dist_audit.xhtml";
        $.ajax(url, {
            type: "POST",
            //data: $("#post_form").serialize(),
            data: data,
            dataType:"html",
            cache:false,
            success:function(a) {
                alert("操作成功");
                window.location.href = "${ctx}/index.xhtml#exam/exam_score.xhtml?p=qual_as&type=${type}&periodDesc=${periodDesc}&workId=${workId}";
            },
            complete:function() {}
        })
	}
</script>